package data;

import java.util.List;

import bean.Component;
import data.exception.DaoException;

/**
 * Component DAO.
 * 
 * @author chuxiaoyuan
 * 
 */
public interface IComponentDao extends IDao<Component> {

	/**
	 * Update component information.
	 * 
	 * Note: the quantity will be ignored! only other fields of componet
	 * information will be updated.
	 * 
	 * @param component
	 *            the component.
	 * @return the affected rows.
	 * @throws DaoException
	 *             update exception.
	 */
	int updateComponentInfo(Component component) throws DaoException;

	/**
	 * Increase the component quantity by the given number.
	 * 
	 * @param componentId
	 *            the component Id.
	 * @param number
	 *            the number to increase.
	 * @return number of rows affected.
	 * @throws DaoException
	 *             update exception.
	 */
	int increaseComponentQuantity(Long componentId, Long number)
			throws DaoException;

	/**
	 * Decrease the component quantity by the given number.
	 * 
	 * @param componentId
	 *            the component Id.
	 * @param number
	 *            the number to decrease.
	 * @return number of rows affected.
	 * @throws DaoException
	 *             update exception.
	 */
	int decreaseComponentQuantity(Long componentId, Long number)
			throws DaoException;

	/**
	 * Select component by Id.
	 * 
	 * @param componentId
	 *            the component Id.
	 * @return the component. null if not found.
	 * @throws DaoException
	 *             select exception.
	 */
	Component selectById(final Long componentId) throws DaoException;

	/**
	 * Select components by keywords with pagination.
	 * 
	 * @param keyword
	 *            the search key word.
	 * @param pagination
	 *            the pagination.
	 * @return the matched components.
	 * @throws DaoException
	 *             search failed.
	 */
	List<Component> selectByKeywords(String keyword, Pagination pagination)
			throws DaoException;

	/**
	 * Select components by keywords without pagination.
	 * 
	 * @param keyword
	 *            the search key word.
	 * @param pagination
	 *            the pagination.
	 * @return the matched components.
	 * @throws DaoException
	 *             search failed.
	 */
	List<Component> selectByKeywords(String keyword) throws DaoException;
}
